<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>JavaScript数组常用方法 | Closure233</title><meta name="author" content="Closure233"><meta name="copyright" content="Closure233"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="JavaScript数组常用方法1、不改变原数组，返回新数组join()：把数组中所有元素放入一个字符串中，不同元素中间插入join输入的参数，拼接为一个字符串并返回。12const arr &#x3D; [&amp;#x27;hello&amp;#x27;, &amp;#x27;js&amp;#x27;, &amp;#x27;world&amp;#x27;];arr.join(&amp;#x27; &amp;#x27;); &#x2F;&#x2F; hello js world  con">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript数组常用方法">
<meta property="og:url" content="https://closure.gitee.io/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/index.html">
<meta property="og:site_name" content="Closure233">
<meta property="og:description" content="JavaScript数组常用方法1、不改变原数组，返回新数组join()：把数组中所有元素放入一个字符串中，不同元素中间插入join输入的参数，拼接为一个字符串并返回。12const arr &#x3D; [&amp;#x27;hello&amp;#x27;, &amp;#x27;js&amp;#x27;, &amp;#x27;world&amp;#x27;];arr.join(&amp;#x27; &amp;#x27;); &#x2F;&#x2F; hello js world  con">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://closure.gitee.io/images/avatar.gif">
<meta property="article:published_time" content="2023-07-14T07:45:00.000Z">
<meta property="article:modified_time" content="2023-08-08T05:14:27.501Z">
<meta property="article:author" content="Closure233">
<meta property="article:tag" content="js">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://closure.gitee.io/images/avatar.gif"><link rel="shortcut icon" href="/images/moss.ico"><link rel="canonical" href="https://closure.gitee.io/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: true,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'JavaScript数组常用方法',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-08-08 13:14:27'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/images/avatar.gif" onerror="onerror=null;src='/images/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">6</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">0</div></a></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background: url(/images/cover/cover1.jpg)"><nav id="nav"><span id="blog-info"><a href="/" title="Closure233"><span class="site-name">Closure233</span></a></span><div id="menus"><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">JavaScript数组常用方法</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-07-14T07:45:00.000Z" title="Created 2023-07-14 15:45:00">2023-07-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-08-08T05:14:27.501Z" title="Updated 2023-08-08 13:14:27">2023-08-08</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="JavaScript数组常用方法"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="JavaScript数组常用方法"><a href="#JavaScript数组常用方法" class="headerlink" title="JavaScript数组常用方法"></a>JavaScript数组常用方法</h1><h2 id="1、不改变原数组，返回新数组"><a href="#1、不改变原数组，返回新数组" class="headerlink" title="1、不改变原数组，返回新数组"></a>1、不改变原数组，返回新数组</h2><h3 id="join-：把数组中所有元素放入一个字符串中，不同元素中间插入join输入的参数，拼接为一个字符串并返回。"><a href="#join-：把数组中所有元素放入一个字符串中，不同元素中间插入join输入的参数，拼接为一个字符串并返回。" class="headerlink" title="join()：把数组中所有元素放入一个字符串中，不同元素中间插入join输入的参数，拼接为一个字符串并返回。"></a>join()：把数组中所有元素放入一个字符串中，不同元素中间插入join输入的参数，拼接为一个字符串并返回。</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="string">&#x27;hello&#x27;</span>, <span class="string">&#x27;js&#x27;</span>, <span class="string">&#x27;world&#x27;</span>];</span><br><span class="line">arr.<span class="title function_">join</span>(<span class="string">&#x27; &#x27;</span>); <span class="comment">// hello js world</span></span><br></pre></td></tr></table></figure>

<h3 id="concat-：按输入顺序连接多个（含两个）数组，不改变原始数组，返回被连接数组的一个副本，可连续-concat连接。"><a href="#concat-：按输入顺序连接多个（含两个）数组，不改变原始数组，返回被连接数组的一个副本，可连续-concat连接。" class="headerlink" title="concat()：按输入顺序连接多个（含两个）数组，不改变原始数组，返回被连接数组的一个副本，可连续 concat连接。"></a>concat()：按输入顺序连接多个（含两个）数组，不改变原始数组，返回被连接数组的一个副本，可连续 <code>concat</code>连接。</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr1 = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line"><span class="keyword">const</span> arr2 = [<span class="string">&#x27;hello&#x27;</span>, <span class="string">&#x27;js&#x27;</span>, <span class="string">&#x27;world&#x27;</span>];</span><br><span class="line"><span class="keyword">const</span> arr3 = [<span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>];</span><br><span class="line">arr.<span class="title function_">concat</span>(arr1, arr2).<span class="title function_">concat</span>(<span class="number">8</span>, <span class="number">9</span>); <span class="comment">// [1, 2, 3, 4, &#x27;hello&#x27;, &#x27;js&#x27;, &#x27;world&#x27;, 5, 6, 7, 8, 9 ]</span></span><br></pre></td></tr></table></figure>

<h3 id="slice-：从开始到结束（-左闭右开，即不包括结束）选择数组的一部分浅拷贝到一个新数组。"><a href="#slice-：从开始到结束（-左闭右开，即不包括结束）选择数组的一部分浅拷贝到一个新数组。" class="headerlink" title="slice()：从开始到结束（[)左闭右开，即不包括结束）选择数组的一部分浅拷贝到一个新数组。"></a>slice()：从开始到结束（<code>[)</code>左闭右开，即不包括结束）选择数组的一部分<strong>浅拷贝</strong>到一个新数组。</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];</span><br><span class="line">arr.<span class="title function_">slice</span>(<span class="number">1</span>, <span class="number">5</span>); <span class="comment">// [ 1, 2, 3, 4 ]</span></span><br></pre></td></tr></table></figure>

<h3 id="map-：创建一个新数组并返回，新数组的每个元素由原数组中的每一个元素执行提供的函数而来，其中原始数组不会发生改变。、"><a href="#map-：创建一个新数组并返回，新数组的每个元素由原数组中的每一个元素执行提供的函数而来，其中原始数组不会发生改变。、" class="headerlink" title="map()：创建一个新数组并返回，新数组的每个元素由原数组中的每一个元素执行提供的函数而来，其中原始数组不会发生改变。、"></a>map()：创建一个新数组并返回，新数组的每个元素由原数组中的每一个元素执行提供的函数而来，其中原始数组不会发生改变。、</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line">arr.<span class="title function_">map</span>(<span class="function"><span class="params">i</span> =&gt;</span> i * <span class="number">2</span>); <span class="comment">// [2, 4, 6, 8]</span></span><br></pre></td></tr></table></figure>

<h3 id="every-：检测数组所有元素是否都符合指定条件"><a href="#every-：检测数组所有元素是否都符合指定条件" class="headerlink" title="every()：检测数组所有元素是否都符合指定条件."></a>every()：检测数组所有元素是否都符合指定条件.</h3><ul>
<li>如果数组中检测到有一个元素不满足，则整个表达式返回 <code>false</code>，且剩余的元素不会再进行检测；</li>
<li>如果所有元素都满足条件，则返回 <code>true</code>；</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line">arr.<span class="title function_">every</span>(<span class="function"><span class="params">i</span> =&gt;</span> i &gt; <span class="number">2</span>); <span class="comment">// false</span></span><br><span class="line">arr.<span class="title function_">every</span>(<span class="function"><span class="params">i</span> =&gt;</span> i &gt; <span class="number">0</span>); <span class="comment">// true</span></span><br></pre></td></tr></table></figure>

<h3 id="some-：和-every-类似，用于检测数组中的元素是否满足指定条件，不同之处在于some-只要某个元素符合条件即可返回true。"><a href="#some-：和-every-类似，用于检测数组中的元素是否满足指定条件，不同之处在于some-只要某个元素符合条件即可返回true。" class="headerlink" title="some()：和 every() 类似，用于检测数组中的元素是否满足指定条件，不同之处在于some()只要某个元素符合条件即可返回true。"></a>some()：和 <code>every()</code> 类似，用于检测数组中的元素是否满足指定条件，不同之处在于<code>some()</code>只要某个元素符合条件即可返回true。</h3><ul>
<li>如果有一个元素满足条件，则表达式返回 <code>true</code>, 剩余的元素不会再执行检测;</li>
<li>如果没有满足条件的元素，则返回 <code>false</code>;</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line">arr.<span class="title function_">every</span>(<span class="function"><span class="params">i</span> =&gt;</span> i &gt; <span class="number">4</span>); <span class="comment">// false</span></span><br><span class="line">arr.<span class="title function_">every</span>(<span class="function"><span class="params">i</span> =&gt;</span> i &gt; <span class="number">3</span>); <span class="comment">// true</span></span><br></pre></td></tr></table></figure>

<h3 id="filter-：创建一个新的数组，新数组中的元素是通过检查符合条件的所有元素。"><a href="#filter-：创建一个新的数组，新数组中的元素是通过检查符合条件的所有元素。" class="headerlink" title="filter()：创建一个新的数组，新数组中的元素是通过检查符合条件的所有元素。"></a>filter()：创建一个新的数组，新数组中的元素是通过检查符合条件的所有元素。</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line">arr.<span class="title function_">filter</span>(<span class="function"><span class="params">i</span> =&gt;</span> i &gt; <span class="number">2</span>); <span class="comment">// [3, 4]</span></span><br></pre></td></tr></table></figure>

<h3 id="forEach-：用于遍历数组，并将数组元素传递给回调函数，返回undefined"><a href="#forEach-：用于遍历数组，并将数组元素传递给回调函数，返回undefined" class="headerlink" title="forEach()：用于遍历数组，并将数组元素传递给回调函数，返回undefined"></a>forEach()：用于遍历数组，并将数组元素传递给回调函数，返回<code>undefined</code></h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line"><span class="keyword">const</span> newArr = [];</span><br><span class="line">arr.<span class="title function_">forEach</span>(<span class="function"><span class="params">i</span> =&gt;</span> newArr.<span class="title function_">push</span>(i * <span class="number">2</span>)); <span class="comment">// newArr: [2, 4, 6, 8]</span></span><br></pre></td></tr></table></figure>

<h3 id="reduce-：接受一个函数作为累加器，数组中的每个值（从左到右）开始递减，最终计算为一个值。若是空数组则不执行回调函数。"><a href="#reduce-：接受一个函数作为累加器，数组中的每个值（从左到右）开始递减，最终计算为一个值。若是空数组则不执行回调函数。" class="headerlink" title="reduce()：接受一个函数作为累加器，数组中的每个值（从左到右）开始递减，最终计算为一个值。若是空数组则不执行回调函数。"></a>reduce()：接受一个函数作为累加器，数组中的每个值（从左到右）开始递减，最终计算为一个值。若是空数组则不执行回调函数。</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line">arr.<span class="title function_">reduce</span>(<span class="function">(<span class="params">prev, cur</span>) =&gt;</span> prev + cur, <span class="number">0</span>); <span class="comment">// 从index=0开始，计算数组元素和，返回 6</span></span><br></pre></td></tr></table></figure>

<h2 id="2、改变原数组"><a href="#2、改变原数组" class="headerlink" title="2、改变原数组"></a>2、改变原数组</h2><h3 id="push-：向数组末尾增加一个或多个元素，返回改变后数组的长度"><a href="#push-：向数组末尾增加一个或多个元素，返回改变后数组的长度" class="headerlink" title="push()：向数组末尾增加一个或多个元素，返回改变后数组的长度"></a>push()：向数组末尾增加一个或多个元素，返回改变后数组的长度</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line">arr.<span class="title function_">push</span>(<span class="number">4</span>, <span class="number">5</span>); <span class="comment">// arr = [1, 2, 3, 4, 5]，return 5</span></span><br></pre></td></tr></table></figure>

<h3 id="pop-：删除数组最后一个元素，并返回这个元素"><a href="#pop-：删除数组最后一个元素，并返回这个元素" class="headerlink" title="pop()：删除数组最后一个元素，并返回这个元素"></a>pop()：删除数组最后一个元素，并返回这个元素</h3><ul>
<li>如果数组为空，则不改变数组，返 <code>undefined</code>；</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line">arr.<span class="title function_">pop</span>(); <span class="comment">// arr = [1, 2]，return 3</span></span><br><span class="line"><span class="keyword">const</span> arr2 = [];</span><br><span class="line">arr2.<span class="title function_">pop</span>(); <span class="comment">// return undefined</span></span><br></pre></td></tr></table></figure>

<h3 id="shift-：删除数组的第一个元素，并返回这个元素"><a href="#shift-：删除数组的第一个元素，并返回这个元素" class="headerlink" title="shift()：删除数组的第一个元素，并返回这个元素"></a>shift()：删除数组的第一个元素，并返回这个元素</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line">arr.<span class="title function_">shift</span>(); <span class="comment">// return 1</span></span><br></pre></td></tr></table></figure>

<h3 id="unshift-：将一个或多个元素添加到数组的开头，返回改变后数组的长度"><a href="#unshift-：将一个或多个元素添加到数组的开头，返回改变后数组的长度" class="headerlink" title="unshift()：将一个或多个元素添加到数组的开头，返回改变后数组的长度"></a>unshift()：将一个或多个元素添加到数组的开头，返回改变后数组的长度</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line">arr.<span class="title function_">unshift</span>(<span class="number">4</span>, <span class="number">5</span>); <span class="comment">// arr 变为 [4, 5, 1, 2, 3], return 5</span></span><br><span class="line">arr.<span class="title function_">unshift</span>([<span class="number">6</span>, <span class="number">7</span>]); <span class="comment">// arr 变为 [[6, 7], 4, 5, 1, 2, 3], return 6</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="reverse-：颠倒数组中元素的位置，返回该数组的引用"><a href="#reverse-：颠倒数组中元素的位置，返回该数组的引用" class="headerlink" title="reverse()：颠倒数组中元素的位置，返回该数组的引用"></a>reverse()：颠倒数组中元素的位置，返回该数组的引用</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line">arr.<span class="title function_">reverse</span>(); <span class="comment">// arr 变为 [3, 2, 1], return arr的引用</span></span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<h3 id="sort-：对数组的元素进行排序，并返回数组。排序不一定是稳定的。默认排序顺序是根据字符串-Unicode-码点。"><a href="#sort-：对数组的元素进行排序，并返回数组。排序不一定是稳定的。默认排序顺序是根据字符串-Unicode-码点。" class="headerlink" title="sort()：对数组的元素进行排序，并返回数组。排序不一定是稳定的。默认排序顺序是根据字符串 Unicode 码点。"></a>sort()：对数组的元素进行排序，并返回数组。排序不一定是稳定的。默认排序顺序是根据字符串 Unicode 码点。</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">10</span>, <span class="number">12</span>, <span class="number">22</span>];</span><br><span class="line">arr.<span class="title function_">sort</span>(); <span class="comment">// [ 1, 10, 12, 2, 22, 3, 4];</span></span><br></pre></td></tr></table></figure>

<h3 id="splice-：向数组中添加-删除元素，返回被删除的项目"><a href="#splice-：向数组中添加-删除元素，返回被删除的项目" class="headerlink" title="splice()：向数组中添加/删除元素，返回被删除的项目"></a>splice()：向数组中添加/删除元素，返回被删除的项目</h3><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line"><span class="comment">// splice(start, deleteCount, item0, item1)</span></span><br><span class="line">arr.<span class="title function_">splice</span>(<span class="number">1</span>, <span class="number">2</span>, <span class="number">10</span>, <span class="number">12</span>); <span class="comment">// arr 变为 [1, 10, 12, 4], return [2, 3]</span></span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a target="_blank" rel="noopener" href="https://gitee.com/closure233">Closure233</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://closure.gitee.io/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/">https://closure.gitee.io/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/js/">js</a></div><div class="post_share"><div class="social-share" data-image="/images/avatar.gif" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/08/04/JavaScript%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E5%92%8CPromise/" title="JavaScript异步编程和Promise"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">JavaScript异步编程和Promise</div></div></a></div><div class="next-post pull-right"><a href="/2023/06/21/%E7%AE%80%E5%8D%95%E7%9A%84CSS%E6%95%88%E6%9E%9C%E5%AE%9E%E7%8E%B0/" title="简单的CSS效果实现"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">简单的CSS效果实现</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>Related Articles</span></div><div class="relatedPosts-list"><div><a href="/2023/05/10/JavaScript%E7%9A%84%E5%86%92%E6%B3%A1%E5%92%8C%E6%8D%95%E8%8E%B7/" title="JavaScript的冒泡和捕获"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-05-10</div><div class="title">JavaScript的冒泡和捕获</div></div></a></div><div><a href="/2023/05/08/JavaScript%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%92%8C%E9%9A%90%E5%BC%8F%E8%BD%AC%E6%8D%A2/" title="JavaScript的数据类型和隐式转换"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-05-08</div><div class="title">JavaScript的数据类型和隐式转换</div></div></a></div><div><a href="/2023/05/20/JavaScript%E7%9A%84%E5%8E%9F%E5%9E%8B%E5%92%8C%E5%8E%9F%E5%9E%8B%E9%93%BE/" title="JavaScript的原型和原型链"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-05-20</div><div class="title">JavaScript的原型和原型链</div></div></a></div><div><a href="/2023/08/04/JavaScript%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E5%92%8CPromise/" title="JavaScript异步编程和Promise"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-08-04</div><div class="title">JavaScript异步编程和Promise</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/images/avatar.gif" onerror="this.onerror=null;this.src='/images/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Closure233</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">6</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/catfish233"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95"><span class="toc-number">1.</span> <span class="toc-text">JavaScript数组常用方法</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1%E3%80%81%E4%B8%8D%E6%94%B9%E5%8F%98%E5%8E%9F%E6%95%B0%E7%BB%84%EF%BC%8C%E8%BF%94%E5%9B%9E%E6%96%B0%E6%95%B0%E7%BB%84"><span class="toc-number">1.1.</span> <span class="toc-text">1、不改变原数组，返回新数组</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#join-%EF%BC%9A%E6%8A%8A%E6%95%B0%E7%BB%84%E4%B8%AD%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E6%94%BE%E5%85%A5%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%EF%BC%8C%E4%B8%8D%E5%90%8C%E5%85%83%E7%B4%A0%E4%B8%AD%E9%97%B4%E6%8F%92%E5%85%A5join%E8%BE%93%E5%85%A5%E7%9A%84%E5%8F%82%E6%95%B0%EF%BC%8C%E6%8B%BC%E6%8E%A5%E4%B8%BA%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B9%B6%E8%BF%94%E5%9B%9E%E3%80%82"><span class="toc-number">1.1.1.</span> <span class="toc-text">join()：把数组中所有元素放入一个字符串中，不同元素中间插入join输入的参数，拼接为一个字符串并返回。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#concat-%EF%BC%9A%E6%8C%89%E8%BE%93%E5%85%A5%E9%A1%BA%E5%BA%8F%E8%BF%9E%E6%8E%A5%E5%A4%9A%E4%B8%AA%EF%BC%88%E5%90%AB%E4%B8%A4%E4%B8%AA%EF%BC%89%E6%95%B0%E7%BB%84%EF%BC%8C%E4%B8%8D%E6%94%B9%E5%8F%98%E5%8E%9F%E5%A7%8B%E6%95%B0%E7%BB%84%EF%BC%8C%E8%BF%94%E5%9B%9E%E8%A2%AB%E8%BF%9E%E6%8E%A5%E6%95%B0%E7%BB%84%E7%9A%84%E4%B8%80%E4%B8%AA%E5%89%AF%E6%9C%AC%EF%BC%8C%E5%8F%AF%E8%BF%9E%E7%BB%AD-concat%E8%BF%9E%E6%8E%A5%E3%80%82"><span class="toc-number">1.1.2.</span> <span class="toc-text">concat()：按输入顺序连接多个（含两个）数组，不改变原始数组，返回被连接数组的一个副本，可连续 concat连接。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#slice-%EF%BC%9A%E4%BB%8E%E5%BC%80%E5%A7%8B%E5%88%B0%E7%BB%93%E6%9D%9F%EF%BC%88-%E5%B7%A6%E9%97%AD%E5%8F%B3%E5%BC%80%EF%BC%8C%E5%8D%B3%E4%B8%8D%E5%8C%85%E6%8B%AC%E7%BB%93%E6%9D%9F%EF%BC%89%E9%80%89%E6%8B%A9%E6%95%B0%E7%BB%84%E7%9A%84%E4%B8%80%E9%83%A8%E5%88%86%E6%B5%85%E6%8B%B7%E8%B4%9D%E5%88%B0%E4%B8%80%E4%B8%AA%E6%96%B0%E6%95%B0%E7%BB%84%E3%80%82"><span class="toc-number">1.1.3.</span> <span class="toc-text">slice()：从开始到结束（[)左闭右开，即不包括结束）选择数组的一部分浅拷贝到一个新数组。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#map-%EF%BC%9A%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%96%B0%E6%95%B0%E7%BB%84%E5%B9%B6%E8%BF%94%E5%9B%9E%EF%BC%8C%E6%96%B0%E6%95%B0%E7%BB%84%E7%9A%84%E6%AF%8F%E4%B8%AA%E5%85%83%E7%B4%A0%E7%94%B1%E5%8E%9F%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%AF%8F%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E6%89%A7%E8%A1%8C%E6%8F%90%E4%BE%9B%E7%9A%84%E5%87%BD%E6%95%B0%E8%80%8C%E6%9D%A5%EF%BC%8C%E5%85%B6%E4%B8%AD%E5%8E%9F%E5%A7%8B%E6%95%B0%E7%BB%84%E4%B8%8D%E4%BC%9A%E5%8F%91%E7%94%9F%E6%94%B9%E5%8F%98%E3%80%82%E3%80%81"><span class="toc-number">1.1.4.</span> <span class="toc-text">map()：创建一个新数组并返回，新数组的每个元素由原数组中的每一个元素执行提供的函数而来，其中原始数组不会发生改变。、</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#every-%EF%BC%9A%E6%A3%80%E6%B5%8B%E6%95%B0%E7%BB%84%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E6%98%AF%E5%90%A6%E9%83%BD%E7%AC%A6%E5%90%88%E6%8C%87%E5%AE%9A%E6%9D%A1%E4%BB%B6"><span class="toc-number">1.1.5.</span> <span class="toc-text">every()：检测数组所有元素是否都符合指定条件.</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#some-%EF%BC%9A%E5%92%8C-every-%E7%B1%BB%E4%BC%BC%EF%BC%8C%E7%94%A8%E4%BA%8E%E6%A3%80%E6%B5%8B%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E5%85%83%E7%B4%A0%E6%98%AF%E5%90%A6%E6%BB%A1%E8%B6%B3%E6%8C%87%E5%AE%9A%E6%9D%A1%E4%BB%B6%EF%BC%8C%E4%B8%8D%E5%90%8C%E4%B9%8B%E5%A4%84%E5%9C%A8%E4%BA%8Esome-%E5%8F%AA%E8%A6%81%E6%9F%90%E4%B8%AA%E5%85%83%E7%B4%A0%E7%AC%A6%E5%90%88%E6%9D%A1%E4%BB%B6%E5%8D%B3%E5%8F%AF%E8%BF%94%E5%9B%9Etrue%E3%80%82"><span class="toc-number">1.1.6.</span> <span class="toc-text">some()：和 every() 类似，用于检测数组中的元素是否满足指定条件，不同之处在于some()只要某个元素符合条件即可返回true。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#filter-%EF%BC%9A%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E6%95%B0%E7%BB%84%EF%BC%8C%E6%96%B0%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E5%85%83%E7%B4%A0%E6%98%AF%E9%80%9A%E8%BF%87%E6%A3%80%E6%9F%A5%E7%AC%A6%E5%90%88%E6%9D%A1%E4%BB%B6%E7%9A%84%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E3%80%82"><span class="toc-number">1.1.7.</span> <span class="toc-text">filter()：创建一个新的数组，新数组中的元素是通过检查符合条件的所有元素。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#forEach-%EF%BC%9A%E7%94%A8%E4%BA%8E%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%EF%BC%8C%E5%B9%B6%E5%B0%86%E6%95%B0%E7%BB%84%E5%85%83%E7%B4%A0%E4%BC%A0%E9%80%92%E7%BB%99%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0%EF%BC%8C%E8%BF%94%E5%9B%9Eundefined"><span class="toc-number">1.1.8.</span> <span class="toc-text">forEach()：用于遍历数组，并将数组元素传递给回调函数，返回undefined</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#reduce-%EF%BC%9A%E6%8E%A5%E5%8F%97%E4%B8%80%E4%B8%AA%E5%87%BD%E6%95%B0%E4%BD%9C%E4%B8%BA%E7%B4%AF%E5%8A%A0%E5%99%A8%EF%BC%8C%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%AF%8F%E4%B8%AA%E5%80%BC%EF%BC%88%E4%BB%8E%E5%B7%A6%E5%88%B0%E5%8F%B3%EF%BC%89%E5%BC%80%E5%A7%8B%E9%80%92%E5%87%8F%EF%BC%8C%E6%9C%80%E7%BB%88%E8%AE%A1%E7%AE%97%E4%B8%BA%E4%B8%80%E4%B8%AA%E5%80%BC%E3%80%82%E8%8B%A5%E6%98%AF%E7%A9%BA%E6%95%B0%E7%BB%84%E5%88%99%E4%B8%8D%E6%89%A7%E8%A1%8C%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0%E3%80%82"><span class="toc-number">1.1.9.</span> <span class="toc-text">reduce()：接受一个函数作为累加器，数组中的每个值（从左到右）开始递减，最终计算为一个值。若是空数组则不执行回调函数。</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%E3%80%81%E6%94%B9%E5%8F%98%E5%8E%9F%E6%95%B0%E7%BB%84"><span class="toc-number">1.2.</span> <span class="toc-text">2、改变原数组</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#push-%EF%BC%9A%E5%90%91%E6%95%B0%E7%BB%84%E6%9C%AB%E5%B0%BE%E5%A2%9E%E5%8A%A0%E4%B8%80%E4%B8%AA%E6%88%96%E5%A4%9A%E4%B8%AA%E5%85%83%E7%B4%A0%EF%BC%8C%E8%BF%94%E5%9B%9E%E6%94%B9%E5%8F%98%E5%90%8E%E6%95%B0%E7%BB%84%E7%9A%84%E9%95%BF%E5%BA%A6"><span class="toc-number">1.2.1.</span> <span class="toc-text">push()：向数组末尾增加一个或多个元素，返回改变后数组的长度</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#pop-%EF%BC%9A%E5%88%A0%E9%99%A4%E6%95%B0%E7%BB%84%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%EF%BC%8C%E5%B9%B6%E8%BF%94%E5%9B%9E%E8%BF%99%E4%B8%AA%E5%85%83%E7%B4%A0"><span class="toc-number">1.2.2.</span> <span class="toc-text">pop()：删除数组最后一个元素，并返回这个元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#shift-%EF%BC%9A%E5%88%A0%E9%99%A4%E6%95%B0%E7%BB%84%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%EF%BC%8C%E5%B9%B6%E8%BF%94%E5%9B%9E%E8%BF%99%E4%B8%AA%E5%85%83%E7%B4%A0"><span class="toc-number">1.2.3.</span> <span class="toc-text">shift()：删除数组的第一个元素，并返回这个元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#unshift-%EF%BC%9A%E5%B0%86%E4%B8%80%E4%B8%AA%E6%88%96%E5%A4%9A%E4%B8%AA%E5%85%83%E7%B4%A0%E6%B7%BB%E5%8A%A0%E5%88%B0%E6%95%B0%E7%BB%84%E7%9A%84%E5%BC%80%E5%A4%B4%EF%BC%8C%E8%BF%94%E5%9B%9E%E6%94%B9%E5%8F%98%E5%90%8E%E6%95%B0%E7%BB%84%E7%9A%84%E9%95%BF%E5%BA%A6"><span class="toc-number">1.2.4.</span> <span class="toc-text">unshift()：将一个或多个元素添加到数组的开头，返回改变后数组的长度</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#reverse-%EF%BC%9A%E9%A2%A0%E5%80%92%E6%95%B0%E7%BB%84%E4%B8%AD%E5%85%83%E7%B4%A0%E7%9A%84%E4%BD%8D%E7%BD%AE%EF%BC%8C%E8%BF%94%E5%9B%9E%E8%AF%A5%E6%95%B0%E7%BB%84%E7%9A%84%E5%BC%95%E7%94%A8"><span class="toc-number">1.2.5.</span> <span class="toc-text">reverse()：颠倒数组中元素的位置，返回该数组的引用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#sort-%EF%BC%9A%E5%AF%B9%E6%95%B0%E7%BB%84%E7%9A%84%E5%85%83%E7%B4%A0%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%BA%8F%EF%BC%8C%E5%B9%B6%E8%BF%94%E5%9B%9E%E6%95%B0%E7%BB%84%E3%80%82%E6%8E%92%E5%BA%8F%E4%B8%8D%E4%B8%80%E5%AE%9A%E6%98%AF%E7%A8%B3%E5%AE%9A%E7%9A%84%E3%80%82%E9%BB%98%E8%AE%A4%E6%8E%92%E5%BA%8F%E9%A1%BA%E5%BA%8F%E6%98%AF%E6%A0%B9%E6%8D%AE%E5%AD%97%E7%AC%A6%E4%B8%B2-Unicode-%E7%A0%81%E7%82%B9%E3%80%82"><span class="toc-number">1.2.6.</span> <span class="toc-text">sort()：对数组的元素进行排序，并返回数组。排序不一定是稳定的。默认排序顺序是根据字符串 Unicode 码点。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#splice-%EF%BC%9A%E5%90%91%E6%95%B0%E7%BB%84%E4%B8%AD%E6%B7%BB%E5%8A%A0-%E5%88%A0%E9%99%A4%E5%85%83%E7%B4%A0%EF%BC%8C%E8%BF%94%E5%9B%9E%E8%A2%AB%E5%88%A0%E9%99%A4%E7%9A%84%E9%A1%B9%E7%9B%AE"><span class="toc-number">1.2.7.</span> <span class="toc-text">splice()：向数组中添加&#x2F;删除元素，返回被删除的项目</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/08/08/Axios/" title="Axios"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/08/08/Axios/" title="Axios">Axios</a><time datetime="2023-08-08T03:30:00.000Z" title="Created 2023-08-08 11:30:00">2023-08-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/08/04/Ajax%E8%AF%B7%E6%B1%82/" title="AJAX请求"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/08/04/Ajax%E8%AF%B7%E6%B1%82/" title="AJAX请求">AJAX请求</a><time datetime="2023-08-03T16:12:00.000Z" title="Created 2023-08-04 00:12:00">2023-08-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/08/04/JavaScript%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E5%92%8CPromise/" title="JavaScript异步编程和Promise"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/08/04/JavaScript%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E5%92%8CPromise/" title="JavaScript异步编程和Promise">JavaScript异步编程和Promise</a><time datetime="2023-08-03T16:12:00.000Z" title="Created 2023-08-04 00:12:00">2023-08-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/" title="JavaScript数组常用方法"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/" title="JavaScript数组常用方法">JavaScript数组常用方法</a><time datetime="2023-07-14T07:45:00.000Z" title="Created 2023-07-14 15:45:00">2023-07-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/06/21/%E7%AE%80%E5%8D%95%E7%9A%84CSS%E6%95%88%E6%9E%9C%E5%AE%9E%E7%8E%B0/" title="简单的CSS效果实现"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/06/21/%E7%AE%80%E5%8D%95%E7%9A%84CSS%E6%95%88%E6%9E%9C%E5%AE%9E%E7%8E%B0/" title="简单的CSS效果实现">简单的CSS效果实现</a><time datetime="2023-06-21T05:30:00.000Z" title="Created 2023-06-21 13:30:00">2023-06-21</time></div></div></div></div></div></div></main><footer id="footer" style="background: url(/images/cover/cover1.jpg)"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Closure233</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>